package cn.bugstack.mybatis.binding;

import java.lang.reflect.Proxy;
import java.util.Map;

import cn.bugstack.mybatis.session.SqlSession;

/**
 * description: mapper代理工厂
 * taskId：
 * <pre>
 * change history:
 * date             defect#             person                comments
 * ---------------------------------------------------------------------
 * 2024/8/28       ********         zhaochaoyue        create file
 * </pre>
 *
 * @author: zhaochaoyue
 * @date: 2024/8/28 20:22
 * @copyright: 2024
 */
public class MapperProxyFactory<T> {
    
    private final Class<T> mapperInterface;

    public MapperProxyFactory(Class<T> mapperInterface) {this.mapperInterface = mapperInterface;}
    
    public T newInstance(SqlSession sqlSession){
        final MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession, mapperInterface);
        return (T)Proxy.newProxyInstance(mapperInterface.getClassLoader(),new Class[]{mapperInterface},mapperProxy);
    }
}
